<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-row :gutter="20" class="mgb20" style="margin-top: 40px">
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{ padding: '0px' }">
                            <div class="grid-content grid-con-1">
                                <i class="el-icon-user-solid grid-con-icon "></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">1234</div>
                                    <div>今日招工</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{ padding: '0px' }">
                            <div class="grid-content grid-con-3">
                                <i class="el-icon-user-solid grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">123</div>
                                    <div>今日离职</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{ padding: '0px' }">
                            <div class="grid-content grid-con-2">
                                <i class="el-icon-user-solid grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">123</div>
                                    <div>劳务派遣</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>

                </el-row>
            </el-col>
        </el-row>
<!--      <el-row>-->
<!--&lt;!&ndash;        <el-col :span="24" style="color: #409EFF;font-weight: bold;">智能图表<div class=" bg-purple-dark"></div></el-col>&ndash;&gt;-->
<!--      </el-row>-->
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card shadow="hover">
                    <div id="echart-a"></div>
                    <!--                    <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart>-->
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="hover">
                    <div id="echart-g"></div>
                    <!--                    <schart ref="line" class="schart" canvasId="line" :options="options2"></schart>-->
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card shadow="hover">
                    <div id="echart"></div>
<!--                    <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart>-->
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="hover">
                    <div id="echart-k"></div>
<!--                    <schart ref="line" class="schart" canvasId="line" :options="options2"></schart>-->
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>

import * as echarts from 'echarts';
export default {
    name: "dashboard",
    data() {
        return {
            name: localStorage.getItem("ms_username"),
            todoList: [
                {
                    title: "今天要修复100个bug",
                    status: false
                },
                {
                    title: "今天要修复100个bug",
                    status: false
                },
                {
                    title: "今天要写100行代码加几个bug吧",
                    status: false
                },
                {
                    title: "今天要修复100个bug",
                    status: false
                },
                {
                    title: "今天要修复100个bug",
                    status: true
                },
                {
                    title: "今天要写100行代码加几个bug吧",
                    status: true
                }
            ],
            data: [
                {
                    name: "2018/09/04",
                    value: 1083
                },
                {
                    name: "2018/09/05",
                    value: 941
                },
                {
                    name: "2018/09/06",
                    value: 1139
                },
                {
                    name: "2018/09/07",
                    value: 816
                },
                {
                    name: "2018/09/08",
                    value: 327
                },
                {
                    name: "2018/09/09",
                    value: 228
                },
                {
                    name: "2018/09/10",
                    value: 1065
                }
            ],
            options2: {
                type: "line",
                title: {
                    text: "月度招工趋势图"
                },
                labels: ["6月", "7月", "8月", "9月", "10月"],
                datasets: [
                    {
                        label: "员工数",
                        data: [234, 278, 270, 190, 230]
                    },

                ]
            }
        };
    },
    components: {
    },
    computed: {
        role() {
            return this.name === "admin" ? "超级管理员" : "普通用户";
        }
    },
    mounted() {
        var chartDom = document.getElementById('echart');
        var myChart = echarts.init(chartDom);
        var chartDoms = document.getElementById('echart-k');
        var myCharts = echarts.init(chartDoms);
        var chartDoma = document.getElementById('echart-a');
        var myCharta = echarts.init(chartDoma);
        var chartDog = document.getElementById('echart-g');
        var myChartg = echarts.init(chartDog);
        let option = {
            title: {
                text: '本周招工人数',
            },
            legend: {
                data: ['招工人数',]
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data:["周一", "周二", "周三", "周四", "周五","周六","周日",],
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '直接访问',
                    type: 'bar',
                    barWidth: '60%',
                    data: [10, 52, 200, 334, 390, 330, 220]
                }
            ]
        };
        let options = {
            title: {
                text: '月度招工视图',
            },
            legend: {
                data: ['招工人数',]
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data:["一月", "二月", "三月", "四月", "五月"],
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '招工人数',
                    type: 'line',
                    barWidth: '60%',
                    data: [10, 52, 200, 334, 390, 330, 220]
                }
            ]
        };
        let optiona = {
            color:["#409EFF","#F56C6C","#67C23A"],
            title: {
                text: '今日招聘情况',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'left',
            },
            series: [
                {
                    name: '今日招聘',
                    type: 'pie',
                    radius: '50%',
                    data: [
                        {value: 1048, name: '今日招聘人数'},
                        {value: 135, name: '今日离职人数'},
                        {value: 180, name: '今日派遣人数'},
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        let optiong = {
            title: {
                text: '本月招聘情况',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'left',
            },
            series: [
                {
                    name: '本月招聘',
                    type: 'pie',
                    radius: '50%',
                    data: [
                        {value: 1048, name: '本月招聘人数'},
                        {value: 735, name: '本月离职人数'},
                        {value: 580, name: '本月派遣人数'},
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        myChart.setOption(option);
        myCharts.setOption(options);
        myCharta.setOption(optiona);
        myChartg.setOption(optiong);
        //建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
        window.addEventListener("resize", function () {
            myChart.resize();
            myCharts.resize();
            myCharta.resize();
            myChartg.resize();
        });
    },
    methods: {
        changeDate() {
            const now = new Date().getTime();
            this.data.forEach((item, index) => {
                const date = new Date(now - (6 - index) * 86400000);
                item.name = `${date.getFullYear()}/${date.getMonth() +
                    1}/${date.getDate()}`;
            });
        }
    }
};
</script>

<style scoped>
.el-row {
    margin-bottom: 20px;
}
#echart{
    width: 100%;
    height: 450px;
}
#echart-k{
    width: 100%;
    height: 450px;
}
#echart-g{
    width: 100%;
    height: 450px;
}
#echart-a{
    width: 100%;
    height: 450px;
}
.grid-content {
    display: flex;
    align-items: center;
    height: 160px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 160px;
    height: 160px;
    text-align: center;
    line-height: 160px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 80px;
    height: 80px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 100%;
    height: 300px;
}
</style>
